package com.bruce.service.impl;

import com.bruce.Common.Result;
import com.bruce.Common.Resultcode;
import com.bruce.bean.Course;
import com.bruce.bean.Dto.GradeDto;
import com.bruce.bean.Student;
import com.bruce.dao.CourseDao;
import com.bruce.dao.StudentDao;
import com.bruce.dao.impl.CourseDaoImpl;
import com.bruce.dao.impl.StudentDaoImpl;
import com.bruce.service.StudentService;
import com.bruce.utils.PageUtils;

import java.util.List;

public class StudentServiceImpl implements StudentService {

    StudentDao studentDao=new StudentDaoImpl();
    CourseDao courseDao = new CourseDaoImpl();

    @Override
    public Student studentLogin(Student student) {
        return studentDao.studentLogin(student);
    }

    @Override
    public Result addStudent(Student student) {
        int i = studentDao.addStudent(student);
        if (i<1){
            throw new  RuntimeException(Resultcode.Add_succ.getMess());
        }
        return Result.succ();
    }

    @Override
    public PageUtils<Course> ShowAllStudnetChoiceClass(PageUtils pageUtils) {
         pageUtils = courseDao.FindAllCourse(pageUtils);
        List<Course> course = (List)pageUtils.getRecords();
        if (course.size()<1){
            throw new RuntimeException(Resultcode.Find_err.getMess());
        }
        return pageUtils;
    }

    @Override
    public Boolean isChoiced(String cid,String sid) {
         return  courseDao.isisChoiced(cid, sid);
    }

    @Override
    public Result SureCourse(int cid, int sid) {
//        if (courseDao.isisChoiced(cid,sid)){
//        }
        return null;
    }

    @Override
    public boolean CourseIsTeacher(int cid) {
        return courseDao.CourseIsTeacher(cid);
    }

    @Override
    public Result addCoursetoSC(String cid, String sid) {
        int i = courseDao.addCoursetoSC(cid, sid);
        if ( i<1){
            throw new RuntimeException(Resultcode.Add_Error.getMess());
        }
        return Result.succ();
    }

    @Override
    public Result ExitCouese(String cid, String sid) {
        int i = courseDao.ExitCouese(cid, sid);
        if (i<1){
            throw new RuntimeException(Resultcode.Delect_err.getMess());
        }
        return  Result.succ();
    }

    @Override
    public PageUtils<GradeDto> FindOwnGrade(String sid, int parseInt) {

        return courseDao.FindOwnGrade(sid,parseInt);
    }

}
